package com.pets.controller;


import com.pets.pojo.CourseManagement;
import com.pets.pojo.Users;
import com.pets.service.ICourseManagementService;
import com.pets.service.IUsersService;
import com.pets.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.time.LocalDate;

/**
 * <p>
 * 课程管理 前端控制器
 * </p>
 *
 * @author 小陳同學
 * @since 2024-05-13
 */
@RestController
@RequestMapping("/course-management")
@Api(tags = "课程管理")
public class CourseManagementController {

    @Autowired
    private ICourseManagementService courseManagementService;


    @ApiOperation("创建课程(只能管理员使用)")
    @PostMapping
    public Result register(@RequestBody CourseManagement courseManagement) {
        return courseManagementService.register(courseManagement);
    }

    @ApiOperation("根据id删除课程")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        return courseManagementService.deleteById(id);
    }

    @ApiOperation("修改课程(只能修改课程名称与重新设置课程教练)")
    @PutMapping("/update")
    public Result update(@RequestBody CourseManagement courseManagement) {
        return courseManagementService.update(courseManagement);
    }

    @ApiOperation("查询课程集合，不是分页")
    @GetMapping("/list")
    public Result list(@ApiParam(value = "课程名称筛选")@RequestParam(required = false) String courseName,
                       @ApiParam(value = "开始时间,格式: yyyy-MM-dd", required = true) @RequestParam(required = false)
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
                       @ApiParam(value = "结束时间,格式: yyyy-MM-dd", required = true) @RequestParam(required = false)
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime,
                       @ApiParam(value = "当前登陆人id")@RequestParam(required = true) Integer userID) {
        return courseManagementService.list(courseName,beginTime,endTime,userID);
    }
}
